import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:get/get.dart';
import 'package:raze/lore/chronicle/circle_chronicle.dart';
import 'package:raze/lore/chronicle/community_chronicle.dart';
import 'package:raze/lore/chronicle/diary_chronicle.dart';
import 'package:raze/lore/chronicle/eco_education_chronicle.dart';
import 'package:raze/lore/chronicle/follow_chronicle.dart';
import 'package:raze/lore/chronicle/qna_chronicle.dart';
import 'package:raze/lore/chronicle/user_chronicle.dart';
import 'package:raze/lore/chronicle/whisper_chronicle.dart';
import 'package:raze/potions/raze_constant.dart';
import 'package:raze/potions/spatial_alchemy.dart';

/// 启动页
/// 显示项目Logo和加载动画，初始化状态管理，3秒后自动跳转到主页
class SplashRealms extends StatefulWidget {
  const SplashRealms({super.key});

  @override
  State<SplashRealms> createState() => _SplashRealmsState();
}

class _SplashRealmsState extends State<SplashRealms> {
  @override
  void initState() {
    super.initState();
    _initializeChronicles();
    _navigateToMain();
  }

  /// 初始化全局状态管理
  void _initializeChronicles() {
    Get.put(UserChronicle(), permanent: true);
    Get.put(FollowChronicle(), permanent: true);
    Get.put(EcoEducationChronicle(), permanent: true);
    Get.put(QnAChronicle(), permanent: true);
    Get.put(WhisperChronicle(), permanent: true);
    Get.put(CircleChronicle(), permanent: true);
    Get.put(CommunityChronicle(), permanent: true);
    Get.put(DiaryChronicle(), permanent: true);
  }

  /// 延迟3秒后跳转到主页
  void _navigateToMain() {
    Future.delayed(const Duration(seconds: 3), () {
      if (mounted) {
        Get.offNamed('/main');
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: RazeConstants.background,
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            // Logo图片
            Image.asset(
              'assets/images/small-logo.png',
              width: 101.w,
              height: 101.w,
              fit: BoxFit.contain,
            ),
            // 间距
            40.h.boxHeight,
            // 加载动画
            SpinKitCircle(color: RazeConstants.blue, size: 30.w),
          ],
        ),
      ),
    );
  }
}
